package com.base.look.act;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.base.look.R;
import com.base.look.adapter.SnapAdapter;
import com.base.look.bean.ImageUrl;
import com.google.gson.Gson;
import com.yc.cn.ycgallerylib.recyclerView.GalleryRecyclerView;
import com.yc.cn.ycgallerylib.recyclerView.OnGalleryListener;


import java.util.ArrayList;

@Route(path = "/look/images")
public class LookBigImagesActivity extends Activity {
    private String TAG= "LookBigImagesActivity";
    @Autowired
    public String url;

    @Autowired
    public int position;
    private GalleryRecyclerView recyclerView;
    private TextView textView;
    private ImageUrl imageUrl=new ImageUrl();
    private SnapAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_look_images);
        recyclerView=(GalleryRecyclerView)findViewById(R.id.recyclerView);
        textView=(TextView) findViewById(R.id.tag);
        Gson gson=new Gson();
        imageUrl=gson.fromJson(getIntent().getStringExtra("url"),ImageUrl.class);
        position = getIntent().getIntExtra("position",0);
        adapter = new SnapAdapter(LookBigImagesActivity.this,LookBigImagesActivity.this);
        adapter.setData(imageUrl.getUrlList());
        textView.setText(position+1 + "/" + adapter.getData().size());
        recyclerView
                //设置滑动速度
                .setFlingSpeed(1000)
                //设置adapter
                .setDataAdapter(adapter)
                //设置选中的索引
                .setSelectedPosition(position)
                //设置横向或者竖向，注意需要限制传入类型
                .setOrientation(RecyclerView.HORIZONTAL)
                //设置滚动监听事件
                .setOnGalleryListener(new OnGalleryListener() {
                    @Override
                    public void onInitComplete() {
                        Log.e(TAG,"onInitComplete初始化完成");
                    }

                    @Override
                    public void onPageRelease(boolean isNext,int position) {
                        Log.e(TAG,"释放的监听，释放位置:"+position +" 下一页:"+isNext);
                        if (isNext){
                            Log.e(TAG,"释放的监听，释放位置:"+position +" 下一页:"+isNext);
                        }else {
                            Log.e(TAG,"释放的监听，释放位置:"+position +" 上一页:"+isNext);
                        }
                    }

                    @SuppressLint("SetTextI18n")
                    @Override
                    public void onPageSelected(int position) {
                        Log.e(TAG,"释放的监听，释放位置:"+position +" 当前页:"+position);
                        textView.setText((position + 1) + "/" + adapter.getData().size());
                    }
                })
                //装载
                .setUp();



    }

}

